import numpy as np
ones_arr = np.ones((5,5))
ones_arr
array([[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.]])
ones_arr = np.ones((5,5), dtype = int)
ones_arr
array([[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]])
zeros_arr = np.zeros((3,3), dtype = int)
zeros_arr
array([[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])
ones_arr
array([[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]])
zeros_arr*255
array([[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])
import matplotlib.pyplot as plt
from PIL import Image
%matplotlib inline
Sunflower_img = Image.open(r'E:\Users\Public\Pictures\sunflower.jpg')
type(Sunflower_img)
PIL.JpegImagePlugin.JpegImageFile
Sunflower_arr = np.asarray(Sunflower_img)
type(Sunflower_arr)
numpy.ndarray
Sunflower_arr.shape
(5461, 8192, 3)
plt.imshow(Sunflower_arr)
<matplotlib.image.AxesImage at 0x1a6ba502b00>
Sunflower_red = Sunflower_arr.copy()
#plt.imshow
plt.imshow
<function matplotlib.pyplot.imshow(X, cmap=None, norm=None, *, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, origin=None, extent=None, interpolation_stage=None, filternorm=True, filterrad=4.0, resample=None, url=None, data=None, **kwargs)>
Sunflower_red.shape
(5461, 8192, 3)
plt.imshow(Sunflower_red[:, :, 0])
<matplotlib.image.AxesImage at 0x1a6d4ffe710>
plt.imshow(Sunflower_red[:, :, 0], cmap = 'gray')
<matplotlib.image.AxesImage at 0x1a6e9ca9990>
plt.imshow(Sunflower_red[:, :, 1], cmap = 'PuBu')
<matplotlib.image.AxesImage at 0x1a6e9d1f940>
plt.imshow(Sunflower_red[:, :, 2], cmap= 'autumn')
<matplotlib.image.AxesImage at 0x1a6ef31e6e0>
plt.imshow(Sunflower_red[:,:, 1], cmap= 'BuGn')
<matplotlib.image.AxesImage at 0x1a6ef3a1240>
plt.imshow(Sunflower_red)
<matplotlib.image.AxesImage at 0x1a6f498bc10>
arr1 = np.asarray(Sunflower_img)
type(arr1)
numpy.ndarray
arr1.shape
(5461, 8192, 3)
Sunflower_img1 = arr1.copy()
Sunflower_img1
array([[[114, 173, 217],
[111, 170, 214],
[109, 168, 212],
...,
[ 16, 47, 42],
[ 27, 58, 53],
[ 16, 47, 42]],
[[114, 173, 217],
[111, 170, 214],
[109, 168, 212],
...,
[ 17, 48, 43],
[ 23, 54, 49],
[ 19, 50, 45]],
[[113, 172, 216],
[111, 170, 214],
[110, 169, 213],
...,
[ 17, 48, 43],
[ 16, 47, 42],
[ 22, 53, 48]],
...,
[[ 54, 85, 88],
[ 57, 88, 91],
[ 58, 89, 92],
...,
[ 28, 40, 2],
[ 33, 45, 9],
[ 45, 57, 21]],
[[ 65, 96, 99],
[ 64, 95, 98],
[ 60, 91, 94],
...,
[ 19, 31, 0],
[ 28, 40, 4],
[ 46, 58, 22]],
[[ 71, 102, 105],
[ 67, 98, 101],
[ 57, 88, 91],
...,
[ 35, 47, 9],
[ 28, 40, 4],
[ 26, 38, 2]]], dtype=uint8)
!pip install opencv-python
import matplotlib.pyplot as plt
%matplotlib inline
import cv2
Requirement already satisfied: opencv-python in c:\users\hp\downloads\new folder\envs\tensorflow_env\lib\site-packages (4.8.0.76) Requirement already satisfied: numpy>=1.21.2 in c:\users\hp\downloads\new folder\envs\tensorflow_env\lib\site-packages (from opencv-python) (1.24.3)
img= cv2.imread(r'E:\Users\Public\Pictures\sunflower.jpg')
type(img)
numpy.ndarray
img.shape
(5461, 8192, 3)
fix_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
fix_img
array([[[114, 173, 217],
[111, 170, 214],
[109, 168, 212],
...,
[ 16, 47, 42],
[ 27, 58, 53],
[ 16, 47, 42]],
[[114, 173, 217],
[111, 170, 214],
[109, 168, 212],
...,
[ 17, 48, 43],
[ 23, 54, 49],
[ 19, 50, 45]],
[[113, 172, 216],
[111, 170, 214],
[110, 169, 213],
...,
[ 17, 48, 43],
[ 16, 47, 42],
[ 22, 53, 48]],
...,
[[ 54, 85, 88],
[ 57, 88, 91],
[ 58, 89, 92],
...,
[ 28, 40, 2],
[ 33, 45, 9],
[ 45, 57, 21]],
[[ 65, 96, 99],
[ 64, 95, 98],
[ 60, 91, 94],
...,
[ 19, 31, 0],
[ 28, 40, 4],
[ 46, 58, 22]],
[[ 71, 102, 105],
[ 67, 98, 101],
[ 57, 88, 91],
...,
[ 35, 47, 9],
[ 28, 40, 4],
[ 26, 38, 2]]], dtype=uint8)
plt.imshow(fix_img)
<matplotlib.image.AxesImage at 0x1a69109ae90>
img_gray= cv2.imread(r'E:\Users\Public\Pictures\sunflower.jpg',cv2.IMREAD_GRAYSCALE)
img_gray.shape
(5461, 8192)
img_gray.min()
0
img_gray.max()
255
plt.imshow(img_gray)
<matplotlib.image.AxesImage at 0x1a6e9d66650>
fix_img.shape
(5461, 8192, 3)
plt.imshow(img_gray,cmap= 'magma')
<matplotlib.image.AxesImage at 0x1a6a9316d40>
plt.imshow(img_gray,cmap= 'gray')
<matplotlib.image.AxesImage at 0x1a6a9398d90>
fix_img_1 = cv2.resize(fix_img,(500,367))
w_ratio = 0.5
h_ratio = 0.5
fix_img_2 = cv2.resize(fix_img, (0,0), fix_img, w_ratio,h_ratio)
img3 = cv2.flip(fix_img_2,0)
plt.imshow(img3)
<matplotlib.image.AxesImage at 0x1a6abeec910>
cv2.imwrite('new genai image.jpg', img3)
True
import cv2
myimg =cv2.imread(r'C:\Users\HP\OneDrive\Pictures\shivani pic.jpeg')
cv2.imshow('myimg', myimg)
cv2.waitKey()
import cv2
while True:
cv2.imshow('myimg', myimg)
if cv2.waitKey(1) & 0XFF ==27:
break
cv2.destroyAllWindow()
import cv2
cap = cv2.VideoCapture(0)
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
cv2.imshow('frame', gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()